package com.atguigu.gmall_logger.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName: LoggerControl
 * @Description:
 * @Author: kele
 * @Date: 2021/4/16 12:47
 **/
@RestController
@Slf4j
public class LoggerControl {

    @GetMapping("/applog")
    public String ManageLogger(@RequestParam("param") String data){

        //1、将数据落盘
        saveToDisk(data);

        //2、将数据写入到kafka，作为数仓的ods层
        writeToKafka(data);

        return "ok";
    }

    /**
     * 通过springboot自动生成一个kafka对象
      */
    @Autowired
    KafkaTemplate<String,String> kafka;

    /**
     * 数据写入kafka
     * @param data
     */
    private void writeToKafka(String data) {

        //kafka的配置在resources\application.properties
        kafka.send("ods_log",data);
    }

    //将数据存储在本地磁盘
    private void saveToDisk(String data) {
        log.info(data);
    }

}
